const {DataTypes, sequelize} = require("../config/sequelizeCommon");
const {v4: uuidv4} = require("uuid");
const checkTableExistsQuery = `
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'OrderingSystem' AND table_name = 'ounces'
`;

(() => {
  try {
    const existingTables = sequelize.query(checkTableExistsQuery, {
      type: sequelize.QueryTypes.SELECT,
    });

    const Ounce = sequelize.define("Ounce", {
      id: {
        type: DataTypes.UUID,
        primaryKey: true,
        defaultValue: DataTypes.UUIDV4, // 使用 UUID v4 生成默认值
      },
      Unitname: {
        type: DataTypes.STRING(50),
        allowNull: false,
        comment: "菜品单位",
      },
   
    });

    if (existingTables.length === 0) {
      // 表不存在，创建表
      Ounce.sync();
    }
    module.exports = {Ounce};
  } catch (error) {
    console.error("Error checking or creating menu table:", error);
  }
})();
